#ifndef TTMSGMAP_H
#define TTMSGMAP_H
#include "mySingleton.h"
#include "IttFunc.h"
#include "ttCalcObj_Impl.h"

#include <list>
#include <windows.h>
class ttMsgMap:
	public Singleton<ttMsgMap>
{
private:
	typedef std::list<IttFunc*> TTLIST;
public:
	typedef struct _msgloopvar{
		int m_cx, m_cy;
		bool m_bBuilding, m_bLinking, m_bDragging, m_bDrawDragRect, m_bDragBegin, 
			m_bBuildingAnd, m_bDeleting, m_bSetVal, m_bBuildingOr, m_bBuildingNot;
		int m_lastDragX, m_lastDragY, m_InitDragRectX, m_InitDragRectY, m_crntDragRectX, m_crntDragRectY;
		int m_linkcnt;
		ttPoint* m_linkArr[2];
		HPEN m_hPenBlue, m_hPenRed, m_hPenFlash;
		_msgloopvar();
		int flagfalse();
		int drawLink(HDC hdc, ttPoint *begin, ttPoint *end);
		int readAndInit();
		int writeAndUnint();
		int drawDragRect(HDC hdc);
		bool inRect(int x, int y);
	} msgloopvar;

private:
	TTLIST m_MsgMap;
	IttFunc *m_defFunc;
public:
	msgloopvar m_msglpvar;

private:
	int callDefFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
public:
	ttMsgMap();
	~ttMsgMap();
	int push_front(IttFunc*);
	int run(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
	int setDefFunc(IttFunc *);
	int swaptosmall(int & x, int & y);
};
#endif